package com.cn.jx.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

/**
 * <p>JettyConfig Jetty服务器设置
 * 
 * @author <h1>jiangxu2  2019年11月20日</h1>
 * @version v1.11.20.2019
 * @since 1.0
 * 
 * @see #webServerFactory()
 * 
 */
@Configuration
public class JettyConfig {
	
	/**
	 * 读取属性配置文件 jetty端口
	 */
	@Value("${server.port}")
	private Integer port;
	
	/**
	 * 读取属性配置文件 jetty项目名
	 */
	@Value("${server.servlet.context-path}")
	private String pathcontext;
	
	/**
	 * webService工厂配置
	 * @return
	 */
	@Bean
	public ConfigurableServletWebServerFactory webServerFactory()
	{
	    JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
	    factory.setPort(port);
	    factory.setContextPath(pathcontext);
	    factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/error"));
	    return factory;
	}
}
